﻿namespace LogManager.Core.Infrastructure.Logging
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    public class LogTracker : IDisposable
    {
        private List<LogResult> _logs;
        public ReadOnlyCollection<LogResult> Logs
        {
            get
            {
                return this._logs.AsReadOnly();
            }
        }

        public ILogger Logger { get; private set; }
        public LogTracker(ILogger logger)
        {
            this._logs = new List<LogResult>();
            this.Logger = logger;
            logger.LogAdded += Logger_LogAdded;
        }

        private void Logger_LogAdded(LogResult obj)
        {
            this._logs.Add(obj);
        }

        public virtual void Dispose()
        {
            this.Logger.LogAdded -= Logger_LogAdded;
            this._logs = null;
            this.Logger = null;
        }
    }
}
